<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插入数据</title>
</head>
<body>

<input type="button" onclick="insertUsers()" value="插入数据">
<script src="vendors/mock/mock-min.js"></script>
<script src="vendors/jquery/js/jquery.min.js"></script>
<script>

    var items;

    function insertUsers() {
        Mock.mock("http://localhost:8080/czf.html", {
            "data|10-15": [
                {
                    //id: "@increment()",
                    name: "@cname", //中文名称
                    "role|1": ["教师", "学生"],
                    registerDate: "@datetime()", //日期
                    "status|1": ["激活", "禁用"]
                }
            ],
            success: true,
            code: 200,
            msg: "Success"
        });

        $.getJSON("http://localhost:8080/czf.html", function (response) {
            items = response.data;
            for (var i = 0;i<items.length;i++){
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "http://localhost:8080/save" ,//url
                    data: items[i]
                });
            }
        });
    };


</script>
</body>
</html>